package com.kxf.androidtestdemo.view;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

import androidx.annotation.Nullable;

/**
 * @ProjectName: AndroidTestDemo
 * @Package: com.kxf.androidtestdemo.view
 * @ClassName: MyView
 * @Description: java类作用描述
 * @Author: kuangxuefeng
 * @qq: 1024883177
 * @CreateDate: 2020/6/28 10:49
 */
public class MyView extends View {
    public MyView(Context context) {
        super(context);
        setClickable(true);//设置为可点击才能获取到MotionEvent.ACTION_MOVE
    }

    public MyView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        setClickable(true);//设置为可点击才能获取到MotionEvent.ACTION_MOVE
    }

    public MyView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setClickable(true);//设置为可点击才能获取到MotionEvent.ACTION_MOVE
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        Log.d("MyView", "=====>>>onTouchEvent" + " isClickable=" + isClickable() + "  event=" + event);
         boolean b = super.onTouchEvent(event);
        Log.d("MyView", "=====>>>onTouchEvent" + " isClickable=" + isClickable() + "  b=" + b);
        return b;
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {
        Log.d("MyView", "=====>>>dispatchTouchEvent" + "  event=" + event);
        boolean b = super.dispatchTouchEvent(event);
        Log.d("MyView", "=====>>>dispatchTouchEvent" + "  b=" + b);
        return b;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
    }
}
